#include "dbinterface.h"
#include "log4qt/logger.h"

#ifndef DBSQLITEINTERFACE_H
#define DBSQLITEINTERFACE_H

class DBSqliteInterface : public DBInterface
{
    Q_OBJECT
    LOG4QT_DECLARE_QCLASS_LOGGER
  public:
    explicit DBSqliteInterface(const QString& databasePath, QObject* parent = nullptr);
    ~DBSqliteInterface();

    // 数据库连接管理
    bool openDatabase(const QString& connectionName = QString()) override;
    void closeDatabase() override;
    bool isDatabaseOpen() const override;

    // 数据库初始化
    bool initializeDatabase() override;
    bool createTables() override;

    // 基本CRUD操作
    bool                         insertMowerInfo(const MowerInfoBase& mowerInfo) override;
    bool                         updateMowerInfo(qint32 id, const MowerInfoBase& mowerInfo) override;
    bool                         deleteMowerInfo(qint32 id) override;
    QVector<MowerInfoInDb>       selectMowerInfos() override;
    MowerInfoInDb                selectMowerInfoById(qint32 id) override;
    std::optional<MowerInfoInDb> selectMowerInfosBySn(const QString& sn) override;
    std::optional<MowerInfoInDb> selectMowerInfosByMac(const QString& wifi_mac) override;

    // 事务支持
    bool beginTransaction() override;
    bool commitTransaction() override;
    bool rollbackTransaction() override;

    // 实用功能
    QString lastError() const override;
    bool executeQuery(const QString& query, const QMap<QString, QVariant>& params = QMap<QString, QVariant>()) override;
    bool tableExists(const QString& tableName) override;

  private:
  private:
    QString m_databasePath;
};

#endif  // DBSQLITEINTERFACE_H
